#include "mainwindow.h"

MainWindow::MainWindow(int logMaxLines, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
    this -> ui -> setupUi(this);
    this -> logsLines = 0;
    this -> logMaxLines = logMaxLines;
    setWindowIcon(QPixmap(QString(":/ICO/Resources/ICO/MainIcon.ico")));

    connect(this -> ui -> actionQuit, SIGNAL(triggered()), this, SLOT(close()));
    connect(this -> ui -> buttonClearLogs, SIGNAL(clicked()), this, SLOT(slotClearLogs()));
    connect(this, SIGNAL(signalSetStatusBar(QString,int)), this->ui->statusBar, SLOT(showMessage(QString, int)));    
}

MainWindow::~MainWindow(){
    delete ui;
}


void MainWindow::closeEvent(QCloseEvent *event){
    exit(0);
}


void MainWindow::setRevision(int i){
    this->ui->revision -> setText(QString::number(i));
}


Ui::MainWindow * MainWindow::getUi(){
    return this ->ui ;
}




void MainWindow::setStatusBar(QString text, int time){
    emit signalSetStatusBar(text, time);
}

void MainWindow::slotSetStatusBar(QString text, int time){
    setStatusBar(text, time);
}



void MainWindow::log(QString title, QString content, QColor colorTitle, QColor colorText){
    if (this -> logsLines > this -> logMaxLines){
        this -> ui -> Logs -> clear();
        this -> logsLines = 0;
    }
    this -> ui -> Logs ->appendHtml(QString::number(logsLines + 1) + ". <b><font color=" + colorTitle.name() + ">" + title + " : </font></b><font color=" + colorText.name() + " >" + content + "</font>");
    this -> logsLines++;

}

void MainWindow::log(QString content, QColor color){
    if (this -> logsLines > this -> logMaxLines){
        this -> ui -> Logs -> clear();
        this -> logsLines = 0;
    }
    this -> ui -> Logs ->appendHtml(QString::number(logsLines + 1) + ". <i><font color=" + color.name() + ">" + content+ "</font></i>");
    this -> logsLines++;

}


void MainWindow::slotLog(QString string, QColor color){
    log(string);
}


void MainWindow::slotClearLogs(){
    this -> ui -> Logs -> clear();
    this -> logsLines = 0;
}

void MainWindow::slotLog(QString title, QString content, QColor colorTitle, QColor colorText){
   log(title, content);
}


